package com.example.sonone.quarz.Schedule;


import com.example.sonone.quarz.Schedule.ConfigurerScheduling;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;

/**
 * @fileName：TaskDemo1
 * @createTime：2019/5/20 10:07
 * @author：
 * @version：
 * @description：
 */

@Configuration
public class TaskDemo1 extends ConfigurerScheduling {


    private Boolean isSwitch;


    private String cron;

    @Override
    protected void processTask() {
        // 从 db 获取 缓存获取
        isSwitch = true;

        if (isSwitch) {
            System.out.println("基于接口SchedulingConfigurer 1  的动态定时任务:"
                    + LocalDateTime.now() + "，线程名称：" + Thread.currentThread().getName()
                    + " 线程id：" + Thread.currentThread().getId());
        }
    }

    @Override
    protected String getCron() {

        // 从 db 获取 缓存获取
        cron = "0/20 * * * * ?";

        return cron;
    }
}

